﻿var wineApp = wineApp || {};
wineApp.common = (function() {
    var menuMap = {
        home: "wine_domicon1",
        wine: "wine_domicon4",
        jz: "wine_domicon2",
        my: "wine_domicon5",
    }
    var showFooter = true;
    var buildImgLayout2Col = function(wrapperSelector, list, itemParseFn, enableScroll) {
            var wrapper = $(wrapperSelector);
            $.each(list, function(index, val) {
                var obj = itemParseFn(val);
                if (!$.isEmptyObject(obj)) {
                    var imgDesc = obj.imgDesc == null ? "" : obj.imgDesc;
                    var href = obj.imgLink == null ? "#" : obj.imgLink;
                    var html = "<dl><dt>" +
                        "<a href='" + href + "' rel='external'><img src='" + obj.img + "' height=" + obj.img_w + "'/></a></dt>" + imgDesc + "</dl>"
                    $(wrapperSelector).append(html);
                }
            });
        }
        /**
         * 为每个页面添加footer
         * TODO：要考虑一下链接动态生成的问题
         * @return {[type]} [description]
         */
    var buildFooter = function() {
        if (!showFooter) return;
        var file = $.url().attr('file');
        // if (file == 'index.html') {
        //     wineApp.localStorage.remove('currentMenu');
        // }
        var isRoot = isRootPath();
        var path = isRoot ? "app/" : "";
        var path2 = isRoot ? "" : "../";
        var footer = $('<div>', {
            "data-role": "footer",
            "data-theme": "a",
            "data-position": "fixed",
            "data-tap-toggle": "false",
            "style": "height:50px"
        });
        //初始化菜单
        var count = 1000;
        var menuArray = [{
            href: path2 + 'index.html',
            class: 'wine_domicon1',
            img: path2 + 'images/bom_dr_icon.png',
            text: '首页',
            id: ++count
        }, {
            href: path2 + 'app/wine_list.html',
            class: 'wine_domicon4',
            img: path2 + 'images/bom_gwc_icon.png',
            text: '会员好酒',
            id: ++count
        }, {
            href: 'javascript:void(0)',
            class: 'wine_domicon3',
            id: 'homepage'
        }, {
            href: path2 + 'app/jz.html?cat=1004',
            class: 'wine_domicon2',
            img: path2 + 'images/bom_hj_icon.png',
            text: '百年酒庄',
            id: ++count
        }, {
            href: "#",
            class: 'wine_domicon5',
            img: path2 + 'images/bom_wd_icon.png',
            id: 'myaccount',
            text: '我的'
        }]
        var li = "";
        var currentMenu = wineApp.localStorage.get('currentMenu');
        $.each(menuArray, function(index, val) {
            var cls = val.class;
            if (currentMenu == val.class) {
                val.class = val.class + " wine_bom_select";
                var idx = val.img.indexOf('.png');
                val.img = val.img.substring(0, idx) + "2" + ".png";
            }
            var tmp = '<li class="' + cls + '"><a id="' + val.id + '" href="' + val.href + '" class="' + val.class + '"><img src="' + val.img + '" />' + val.text + '</a></li>';
            if (val.class == "wine_domicon3") {
                tmp = '<li class="wine_domicon3"><a href="' + val.href + '" id="homepage" rel="external" class="wine_domicon3"></a></li>';
            }
            li += tmp;
        });
        var footerHtml =
            '<div class="wine_footer">' +
            '<ul>' + li +
            /*'<li><a href="' + path2 + 'app/daren_list.html" rel="external" class="wine_domicon1"><img src="' + path2 + 'images/bom_dr_icon.png" />达人圈</a></li>' +
            '<li><a href="' + path2 + 'app/wine_list.html" rel="external" class="wine_domicon2"><img src="' + path2 + 'images/bom_hj_icon.png" />红酒</a></li>' +
            '<li><a href="#" id="homepage" rel="external" class="wine_domicon3"></a></li>' +
            '<li><a href="' + path2 + 'app/gwc.html" rel="external" class="wine_domicon4"><img src="' + path2 + 'images/bom_gwc_icon.png" />购物车</a></li>' +
            '<li><a id="myaccount" href="#" rel="external" class="wine_domicon5"><img src="' + path2 + 'images/bom_wd_icon.png" />我的</a></li>' +*/
            '</ul>' +
            '</div>';
        footer.addClass('nav-customer-bar').append(footerHtml);
        //console.log(footerHtml)
        $('[data-role="page"]').append(footerHtml);
        //addFooterMenu();
        $(document.body).on('click', ".wine_footer ul li", function() {
            var currentMenu = $(this).attr('class');
            if (currentMenu === 'wine_domicon3') {
                return;
            }
            wineApp.localStorage.set('currentMenu', currentMenu);
        });
        //初始化人气圈菜单
        $(document.body).on('click', "#homepage", function() {
            if (!verifyLogin()) {
                return;
            }
            var key = wineApp.tool.getKey('check_shopingcar');
            var hasShopCar = wineApp.localStorage.get(key);
            if (hasShopCar === 'Y') {
                window.location.href = path2 + 'app/gwc.html';
            } else {
                window.location.href = path2 + 'app/tjtc.html';
            }
        }).on('click', '#myaccount', function() {
            if (!verifyLogin()) {
                return;
            }
            var isRoot = isRootPath();
            var path2 = isRoot ? "" : "../";
            window.location.href = path2 + 'app/my.html';
        }).on('click', '.share', function() {
            var type = $(this).attr('type');
            shareToWeChat(type);
        });
    }
    var initBarcode = function() {
        var isRoot = isRootPath();
        var key_login_flag = wineApp.CONFIG.STORAGE.PREFIX + '.' + 'login_flag';
        var checkLogin = wineApp.localStorage.get(key_login_flag);
        var path2 = isRoot ? "" : "../";
        if (checkLogin !== "checked") {
            window.location.href = path2 + 'login.html';
        }
        var key = wineApp.CONFIG.STORAGE.PREFIX + '.' + 'userInfo.msg';
        var userInfo = wineApp.localStorage.get(key);
        cordova.plugins.barcodeScanner.scan(function(result) {
            console.log(result);
            var ls = $.parseJSON(result.text);
            loadAddr(ls, userInfo);
        }, function(error) {
            console.log('error:%O', error);
        });
        /* var barcode = '[{"id":"fe7baa8e9c8940c7b321354be9347fbe","price":"320","qty":"1","amount":"320"},{"id":"a364e971e2b2469898e9c67f57806368","price":"1","qty":"2","amount":"2"},{"id":"7760268afc4e4738a5690b4d9ddee167","price":"11800","qty":"1","amount":"11800"},{"id":"b9c92b2de5bf4a76bde5ad6755c5c45c","price":"888","qty":"3","amount":"2664"}]';
         var ls = $.parseJSON(barcode);
         loadAddr(ls,userInfo);*/
    }

    var createOrder = function(wineList, addrId, userInfo) {
        var param = [];
        var isRoot = isRootPath();
        var path2 = isRoot ? "" : "../";
        $.each(wineList, function(index, val) {
            var wineId = val.id;
            var obj = {
                qty: val.qty,
                id: wineId,
                darenUserId: ''
            };
            param.push(obj);
        });
        console.log(param);
        var ajaxUrl = wineApp.CONFIG.API.createorder;
        wineApp.ajax.post(ajaxUrl, {
            param: JSON.stringify(param),
            userId: userInfo.platUser.id
        }).done(function(data) {
            if (data.st == 'ok') {
                var orderId = data.msg;
                var order = orderId.split(',');
                $.each(order, function(index, val) {
                    if (addrId != '') {
                        var url = wineApp.CONFIG.API.orderaddr;
                        wineApp.ajax.post(url, {
                            addId: addrId,
                            orderId: val
                        }, function(data) {
                            console.log(data);
                        });
                        //window.location.href = 'mydj_list.html?type=WAIT_PAY';
                    }
                });
                window.location.href = path2 + 'app/order_more.html?orderId=' + orderId
            }
        });
    }

    var loadAddr = function(wineList, userInfo) {
        var ajaxUrl = wineApp.CONFIG.API.addresslist + '?userId=' + userInfo.platUser.id;
        wineApp.ajax.get(ajaxUrl).done(function(data) {
            console.log(data);
            if (data.st == 'ok') {
                $.each(data.msg, function(index, val) {
                    if (val.isDefault == "1") {
                        addrId = val.id;
                        createOrder(wineList, addrId, userInfo);
                    }
                });
            }
        });
    }
    var checkLoginIfNeeded = function(callback) {
        var loginFlag = wineApp.localStorage.get(wineApp.CONFIG.STORAGE.PREFIX + '.login_flag');
        //登录成功，需要再验证一下登录，才能调用后面的api
        if (loginFlag === "checked") {
            var username = wineApp.localStorage.get(wineApp.CONFIG.STORAGE.PREFIX + '.username');
            var password = wineApp.localStorage.get(wineApp.CONFIG.STORAGE.PREFIX + '.password');
            wineApp.biz.common.login(username, password, function(data) {
                //wineApp.biz.common.saveToStorage(true, data);
                callback();
            });
        }

    }
    var verifyLogin = function(referURL) {
        console.log(window.location.href);
        var isRoot = isRootPath();
        var path2 = isRoot ? "" : "../";
        var key_login_flag = wineApp.CONFIG.STORAGE.PREFIX + '.' + 'login_flag';
        var checkLogin = wineApp.localStorage.get(key_login_flag);
        if (checkLogin !== "checked") {
            var url = "login.html";
            if (!_.isNil(referURL)) {
                url += "?refURL=" + referURL;
            }
            window.location.href = path2 + url;
            return false;
        }
        return true;
    }
    var isShowFooter = function(ifShow) {
            showFooter = ifShow;
        }
        //初始化轮播组件
    var buildCarousel = function(selector, data, itemParseFn, carouselOption) {
        var element = $(selector);
        $.each(data, function(index, val) {
            var content = itemParseFn(val);
            var div = $('<div>', {
                "class": "item"
            });
            div.append(content);
            element.append(div);
        });
        var option = {
            navigation: false, // Show next and prev buttons
            autoPlay: 3000,
            slideSpeed: 300,
            paginationSpeed: 400,
            singleItem: true
        }
        carouselOption = carouselOption || {};
        $.extend(option, carouselOption);

        element.owlCarousel(option);

    }

    var isRootPath = function() {
        var isRoot = true;
        var isMobile = wineApp.ENV.isMobile;
        var directory = $.url().attr('directory');
        var keyword = 'app';
        if (isMobile) {
            keyword = 'www/app';
        }
        if (directory.indexOf(keyword) !== -1) {
            isRoot = false;
        }
        return isRoot;
    }

    var getRelativePath = function() {
        var path = $.url().attr('base') + '/' + 'wineApp/';
        return path;
    }

    getImgName = function(fullPath) {
        var temp = _.split(fullPath, "/");
        if (temp.length > 0) {
            return temp[temp.length - 1];
        }
        return fullPath;

    }

    var initBanner = function() {
        var ajaxUrl = wineApp.CONFIG.API.banner;
        var doSuccess = function(data) {
            var resourceURL = wineApp.tool.getResourceURL();
            wineApp.common.buildCarousel('#owl-demo', data.banners, function(val) {
                var content = '<a href="#">' +
                    '<img class="scale" src="' + resourceURL + '/' + val.obid + '.' + val.ext + '" width=100%/>' +
                    '</a>'
                return content
            });
            //$('img.scale').imageScale();
        }
        var doFail = function() {

        }
        wineApp.ajax.post(ajaxUrl, {
            name: 'banner'
        }).done(doSuccess);
    }


    /**
     * [ 默认为header加回退按钮和菜单]
     * @return {[type]} [description]
     */
    var initHeaderIcon = function(type, needBack, showOption, backUrl) {
        var isRoot = isRootPath();
        var path = isRoot ? "app/" : "../app/";
        var path2 = isRoot ? "" : "../";
        var header = $('.wine_header');
        var wineMore = $('<div>', {
            "class": "wine_more"
        });
        showOption = showOption || {
            camera: false,
            search: true,
            more: true
        };
        if (showOption.search) {
            wineMore.append('<a href="javascript:void(0)" rel="external" class="wine_search_icon"><img src="' + path2 + 'images/r_searchicon.png"/></a>')
        }
        if (showOption.more === false || showOption.more == null) {


        } else {
            wineMore.append('<a class="showMore" href="javascript:void(0)"><img src="' + path2 + 'images/r_more_icon.png" /></a>');
        }



        var back = "";
        if (needBack) {
            back = '<div class="wine_home"><a href="javascript:window.history.go(-1)"><img src="' + path2 + 'images/gohomeicon.png"></a></div>';
            if (backUrl != null) {
                back = '<div class="wine_home"><a href="' + backUrl + '"><img src="' + path2 + 'images/gohomeicon.png"></a></div>';
            }
        }

        header.prepend(wineMore);
        header.append(back);
        if (showOption.more) {
            addMoreActionMenu();
            $(document.body).on('click', '.showMore', function(event) {
                $('#mkuan').show();
            });
            $("body :not('.showMore')").on('click', function() {
                $("#mkuan").hide();
            })
        }
        if (showOption.search) {
            var searchInput = '<div id="searchdiv" class="search" style="padding-left:2px">' +
                '<input id="searchContent"style="width:80%; height:30px;border:0px" placeholder="搜索关键字" /><button id="search" style="width:18.5%;border:0px;font-size:400;">搜索</button>' +
                '</div>'
            $(document.body).on('click', '.wine_search_icon', function(event) {
                $(document).scrollTop(0);
                if ($('#searchdiv').length == 0) {
                    $(searchInput).insertAfter('.wine_header');
                } else {
                    $('#searchdiv').remove();
                }
            });
            $(document.body).on('click', '#search', function(event) {
                var content = $('#searchContent').val();
                if (!_.isEmpty(content)) {
                    window.location.href = path2 + "app/search.html?content=" + content;
                }
            });
            $(document.body).on('keyup', '#searchContent', function(event) {
                if (event.keyCode == 13) {
                    $('#search').trigger('click');
                }
            });
        }
        var key_login_flag = wineApp.CONFIG.STORAGE.PREFIX + '.' + 'login_flag';
        var checkLogin = wineApp.localStorage.get(key_login_flag);
        if (checkLogin === "checked") {
            var key = wineApp.CONFIG.STORAGE.PREFIX + '.' + 'userInfo';
            var userInfo = wineApp.localStorage.get(key);
            if (userInfo) {
                $('.wine_tx img').attr('src', userInfo.headimgurl)
            }
        } else {
            $('.wine_tx').html('')
        }
        if (needBack) {
            $('.wine_tx').html('')
        }
        //$('[data-role="page"]').prepend(header).trigger('create');
    }

    var setSelectedMenu = function(currentMemu) {
        var mappedMenu = menuMap[currentMemu];
        var menu = $('.wine_footer a');
        menu.removeClass("wine_bom_select"); //全部不选中
        $.each(menu, function(index, val) {
            var $val = $(val);
            if (!$val.hasClass('wine_domicon3')) {
                var src = $val.find('img').attr('src').replace('2.png', '.png');
                $val.find('img').attr('src', src);
                if ($val.hasClass(mappedMenu)) {
                    $val.addClass('wine_bom_select');
                    var src = $val.find('img').attr('src').replace('.png', '2.png');
                    $val.find('img').attr('src', src);
                }
            }
        })
    }

    var initTabs = function(tabs) {
        var tab = $(tabs);
        var tabList = [];
        var link = [];
        $.each(tab.find('h2 a'), function(index, val) {
            var tabId = $(this).attr('tab');
            if (!$(this).hasClass('wine_active')) {
                $(tabId).addClass('wine_hide');
            }
            link.push(this);
            tabList.push(tabId);
            $(this).on('click', function(event) {
                $.each(link, function(index, val) {
                    $(val).removeClass('wine_active');
                    $(tabList[index]).addClass('wine_hide');
                });
                $(this).addClass('wine_active');
                $(tabId).removeClass('wine_hide');
                tab.trigger('tabsactivate', [tabId, tabList]);
            })
        });
    }


    var addMoreActionMenu = function() {
        var isRoot = isRootPath();
        var path = isRoot ? "" : "../";
        var tmp =
            '<div class="wine_morekuan" id="mkuan">' +
            '<div class="wine_sjx"></div>' +
            '<ul>' +
            '<li><a href="' + path + 'app/onenews.html?nid=10052" class="search"><img src="' + path + 'images/gywmicon.png" />关于我们</a></li>';
        tmp +=
            '<li><a href="' + path + 'app/onenews.html?nid=10049" id="faq" class="faq"><img src="' + path + 'images/fxicon.png" />常见问题</a></li>' +
            '<li style="display:block"><a href="javascript:void(0);" class="share" type="timeline"><img src="' + path + 'images/fxicon.png" />分享到朋友圈</a></li>' +
            '<li style="display:block"><a href="javascript:void(0);" class="share" type="session"><img src="' + path + 'images/fxicon.png" />分享给好友</a></li>' +
            '</ul>' +
            '</div>';
        $(document.body).append(tmp);

    }

    var shareToWeChat = function(shareType) {
        Wechat.isInstalled(function(data) {
            console.log(data);
        }, function(data) {
            console.log('error:%O', data)
        });
        var scene = Wechat.Scene.TIMELINE;
        if (shareType == "session") {
            scene = Wechat.Scene.SESSION;
        }
        Wechat.share({
            message: {
                title: "安东尼奥",
                description: "安东尼奥",
                thumb: "https://mmbiz.qlogo.cn/mmbiz_png/ZPeUKc755PUusgNzibR8SicxmjqlFr8rzddibCxZulUE9EB5AoiaEP8IvoNk46tUKoeA9PqZ0pzJK8ycnB0oNwdN1A/0?wx_fmt=png",
                media: {
                    type: Wechat.Type.WEBPAGE, // webpage
                    webpageUrl: "http://wine.moqle.com/wx/?plat=100&code=041rNqL40Nd9ZG18rrN40FAkL40rNqLQ&state=null" // webpage
                }
            },
            scene: scene // share to Timeline
        });
    }

    var includeCss = function(cssFile) {
        var isRoot = isRootPath();
        var path2 = isRoot ? "" : "../";
        $("<link>")
            .attr({
                rel: "stylesheet",
                type: "text/css",
                href: path2 + cssFile
            }).appendTo("head");
    }

    var checkToken = function() {
        var token = wineApp.ajax.getCert();
        //如果在localstorage里面没有获取到cert，就调用API获取，然后写到localstorage
        if (_.isNull(token) || _.isUndefined(token)) {
            var ajaxUrl = wineApp.CONFIG.API.token;
            var key = _.now()
            var promise = wineApp.ajax.post(ajaxUrl, {
                key: key,
                plat: 100,
                async: false,
                comefrom: 'app'
            })
            promise.done(function(data) {
                var key = wineApp.tool.getKey('APP_CERT');
                if (data.appsecret) {
                    wineApp.localStorage.set(key, data.appsecret);
                } else {
                    var cert = CryptoJS.MD5(data.ram + CryptoJS.MD5(key).toString()).toString();
                    wineApp.localStorage.set(key, cert);
                }

            });
        }
    }

    var checkShopCar = function() {
        var shopcar = function() {
            var ajaxUrl = wineApp.CONFIG.API.cartget;
            var key = wineApp.tool.getKey('check_shopingcar');
            wineApp.localStorage.set(key, 'N');
            wineApp.ajax.post(ajaxUrl, {}).done(function(data) {
                if (data.list.length > 0) {
                    wineApp.localStorage.set(key, 'Y');
                }
            })
        }
        checkLoginIfNeeded(shopcar);
    }
    return {
        buildImgLayout2Col: buildImgLayout2Col,
        buildFooter: buildFooter,
        initHeaderIcon: initHeaderIcon,
        buildCarousel: buildCarousel,
        isRootPath: isRootPath,
        initTabs: initTabs,
        includeCss: includeCss,
        checkToken: checkToken,
        checkShopCar: checkShopCar,
        getImgName: getImgName,
        verifyLogin: verifyLogin,
        initBanner: initBanner,
        setSelectedMenu: setSelectedMenu
    }
})();

wineApp.tool = (function() {
    var getKey = function(key) {
        return wineApp.CONFIG.STORAGE.PREFIX + '.' + key;
    }

    var getResourceURL = function() {
        return wineApp.CONFIG.CONSTANTS.PROTOCOL + '://' + wineApp.CONFIG.CONSTANTS.HOST + ':' + wineApp.CONFIG.CONSTANTS.PORT + wineApp.CONFIG.CONSTANTS.PATH;
    }

    var getScreenWidth = function() {
        return $(window).width();
    }
    var getBaseApiURL = function() {
            return wineApp.CONFIG.API.URL.PROTOCOL + '://' + wineApp.CONFIG.API.URL.HOST + ':' + wineApp.CONFIG.API.URL.PORT + '/' + wineApp.CONFIG.API.URL.PATH + '/';
        }
        /**
         * [toastMsg description]
         * @param  {[type]} message [description]
         * @param  {[type]} title   [description]
         * @param  {[type]} poision [toast-top-right,toast-bottom-right，
         * toast-bottom-left,toast-top-left,toast-top-full-width,
         * toast-bottom-full-width,toast-top-center]
         * @return {[type]}         [description]
         */
    var toastMsg = function(type, message, title, poision) {
        if (toastr) {
            var poision = null ? 'toast-top-full-width' : poision;
            toastr.options = {
                "positionClass": poision
            }
            toastr[type](message, title);
        } else {
            console.log('taostr not define')
        }
    }



    var formateDate = function(date, fmt) {
        var o = {
            "M+": date.getMonth() + 1, //月份   
            "d+": date.getDate(), //日   
            "h+": date.getHours(), //小时   
            "m+": date.getMinutes(), //分   
            "s+": date.getSeconds(), //秒   
            "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
            "S": date.getMilliseconds() //毫秒   
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

    var checkNetWork = function() {
        // var ajaxUrl = wineApp.CONFIG.API.jzdetail
        // wineApp.ajax.post(ajaxUrl, {
        //     id: "10052"
        // }).fail(function(jqXHR) {
        //     if (jqXHR.status === 0 && jqXHR.statusText === "error") {
        //         alert('网络连接异常，请稍后再试');
        //     }
        //     if (jqXHR.statusText === "timeout") {
        //         alert('网络连接超时，请稍后再试');
        //     }
        // });
        var network = navigator.connection.type;
        if (network == Connection.UNKNOWN || network == Connection.NONE) {
            alert('网络连接异常，请稍后再试!');
        }
    }

    saveImgToLocal = function(url) {
        var canvas, context, imageDataUrl, imageData;
        var img = new Image();
        img.onload = function() {
            canvas = document.createElement('canvas');
            canvas.width = img.width;
            canvas.height = img.height;
            context = canvas.getContext('2d');
            context.drawImage(img, 0, 0);
            window.canvas2ImagePlugin.saveImageDataToLibrary(
                function(msg) {
                    console.log(msg);
                },
                function(err) {
                    console.log(err);
                },
                canvas
            );
        };
        img.src = url;
    }

    //用这个函数需要引入 layer.js, hammer.js, jquery.hammer.js, layer.css
    //参数selector 一定要指向 image 元素
    saveImgToLocalExt = function(selector) {
        var element = 'img'
        if (selector) {
            element = selector;
        }
        $(element).hammer().bind("press", function(ev) {
            var url = $(this).attr("src");
            console.log(url);
            showLayer(url);
        });
    }

    var showLayer = function(url) {
        layer.open({
            content: '保存图片?',
            btn: ['确定', '取消'],
            skin: 'footer',
            yes: function(index) {
                wineApp.tool.saveImgToLocal();
                layer.close(index);
            }
        });
    }
    var convertVertoInt = function(version) {
        var tmp = _.replace(version, /\./g, '');
        return parseInt(tmp, 10);
    }
    var randomString = function(len, an) {
        an = an && an.toLowerCase();
        var str = "",
            i = 0,
            min = an == "a" ? 10 : 0,
            max = an == "n" ? 10 : 62;
        for (; i++ < len;) {
            var r = Math.random() * (max - min) + min << 0;
            str += String.fromCharCode(r += r > 9 ? r < 36 ? 55 : 61 : 48);
        }
        return str;
    }

    return {
        getKey: getKey,
        getBaseApiURL: getBaseApiURL,
        getResourceURL: getResourceURL,
        getScreenWidth: getScreenWidth,
        formateDate: formateDate,
        checkNetWork: checkNetWork,
        saveImgToLocal: saveImgToLocal,
        saveImgToLocalExt: saveImgToLocalExt,
        randomString: randomString,
        convertVertoInt: convertVertoInt,
        toastSuccess: function(message, title, poision) {
            return toastMsg('success', message, title, poision);
        },
        toastError: function(message, title, poision) {
            return toastMsg('error', message, title, poision);
        }
    }
})();


document.addEventListener("deviceready", function() {
    //如果框架加载成功，就获取设备uuid，放入本地存储
    wineApp.tool.checkNetWork();
}, false);

$(document).ready(function() {
    wineApp.common.buildFooter();
    var platform = wineApp.ENV.platform;
    if (platform === 'ios') {
        wineApp.common.includeCss('css/ios.css');
    }
});